
import React from 'react';

// [=]



class List extends React.Component {
  state={
    list:[
      {
        name:'张三',
        age:18
      },
      {
        name:'李四',
        age:20
      },
      {
        name:'王五',
        age:36
      },
    ]
  }
  handleListClick = (name,age) =>{
    alert(`名字是${name},年龄是${age}`)

  }
  render() {

    let listHtml = this.state.list.map((item,i)=>(
      <li  onClick={()=>{
        this.handleListClick(item.name,item.age)
      }} >
        <div>名字: {item.name} </div>
        <div>年龄: {item.age} </div>
      </li>
    ))
    return (
      <div>
        <h1>react的列表循环</h1>
        <ul>{listHtml}</ul>
      </div>
    )
  }
}


export default List